package com.ruoyi.livedemo.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import java.io.File;

@Configuration
public class StorageInitializer {
    private static final Logger log = LoggerFactory.getLogger(StorageInitializer.class);

    @Value("${app.storage.root-path:uploads}")
    private String rootPath;

    @PostConstruct
    public void ensureStorageDir() {
        File dir = new File(rootPath);
        if (!dir.exists()) {
            boolean created = dir.mkdirs();
            if (created) {
                log.info("Created storage directory at: {}", dir.getAbsolutePath());
            } else {
                log.warn("Failed to create storage directory at: {}", dir.getAbsolutePath());
            }
        } else if (!dir.isDirectory()) {
            log.warn("Configured storage path is not a directory: {}", dir.getAbsolutePath());
        }
    }
}

